---
slug: 操作记录-生成宽表 #路径，不能重复
title: 操作记录-生成宽表 # 标题
authors: [] # 作者，在authors.yml配置
tags: [facebook, hello, docusaurus] # 标签，在tags.yml配置
toc_min_heading_level: 2 # 最小展示标题
toc_max_heading_level: 5 # 最大展示标题
---

## 生成宽表

##### 宽表注释
```json

{
  "association": [
    {
      "table": "user",
      "association_column": "id",
      "is_width_column_name": true
    },
    {
      "table": "org",
      "association_column": "u_id",
      "is_width_column_name": false
    }
  ],
  "diff": [
        [
          {
            "table": "org",
            "column_name": "org_name",
            "is_width_column_name": false,
            "is_first_width_column_value": true
          },
          {
            "table": "user",
            "column_name": "user_name",
            "is_width_column_name": false,
            "is_first_width_column_value": false
          }
        ],
        [
          {
            "table": "org",
            "column_name": "org_code",
            "is_width_column_name": false,
            "is_first_width_column_value": false
          },
          {
            "table": "user",
            "column_name": "user_code",
            "is_width_column_name": false,
            "is_first_width_column_value": false
          }
        ]
    ]
}
```


```java
String tableName = "log_";
		String table = tables.stream().reduce((a, b) -> a + "_" + b).orElse("").substring(0,8);

		String column = columnList.stream().reduce((a, b) -> a + "_" + b).orElse("");
		tableName+=table+"_"+column;
		return tableName+"_"+diffColumnId;

```


#### 测试-保存

```json
{
  "id": "",
  "jobName": "测试-zj",
  "createTime": "",
  "executeTime": "",
  "remark": "测试",
  "relation": [
    {
      "id": "",
      "tableName": "registerrecord",
      "tableField": "PATIENT_ID",
      "infoId": ""
    },
    {
      "id": "",
      "tableName": "medicalrecord",
      "tableField": "PATIENT_ID",
      "infoId": ""
    }
  ],
  "diffColumnList": [
    {
      "id": "",
      "infoId": "",
      "executeTime": "",
      "executeResult": "",
      "handlerInfo": "",
      "remark": "",
      "columnList": [
        {
          "id": "",
          "diffColumnId": "",
          "tableName": "medicalrecord",
          "columnName": "BIRTHDAY"
        },
        {
          "id": "",
          "diffColumnId": "",
          "tableName": "registerrecord",
          "columnName": "BIRTHDAY"
        }
      ]
    },
{
      "id": "",
      "infoId": "",
      "executeTime": "",
      "executeResult": "",
      "handlerInfo": "",
      "remark": "",
      "columnList": [
        {
          "id": "",
          "diffColumnId": "",
          "tableName": "medicalrecord",
          "columnName": "NAME"
        },
        {
          "id": "",
          "diffColumnId": "",
          "tableName": "registerrecord",
          "columnName": "NAME"
        }
      ]
    }
  ]
}


```


##### 数据差异展示

```json
[
  [
    {
      "id": {
          "column": "id",
          "value": "1",
          "diff": false,
          "key": true
      }
    },
    {
    "name": {
      "column": "name",
      "value": "zj",
      "diff": false
    }
    }

]
]

```

返回结果

```json
{
  "code": 200,
  "success": true,
  "data": [
    [
      {
        "column": "id", //字段名
        "diff": false, //是否有差异 true有,false无
        "value": "9999343069",//值
        "key": true ,//是否是主键
      },
      {
        "column": "BIRTHDAY",
        "diff": true,
        "value": "20241029",
        "key": false
      },
      {
        "column": "NAME",
        "diff": false,
        "value": "",
        "key": false
      }
    ]
]
}

```


处理数据结构
一个主键下的
```json
[
    {
      "id": "name",
      "table_1": "zs",
      "table_2": "ls",
      "table_3": "ww",
      "choose": "table_1"
    },
    {
      "id": "code",
      "table_1": "1",
      "table_2": "2",
      "table_3": "3",
      "choose": "table_2"
    }
]

```